import { fetch, post } from 'plugins/axios'
import { Dialog } from 'quasar'

export function loadTable ({state, commit}) {
  return new Promise((resolve, reject) => {
    state.loading = true
    fetch('/salt/minions_keys/', {
    }).then((response) => {
      commit('loadTableSuccess', response)
      resolve()
    }).catch((error) => {
      state.etext = error.response
    })
  })
}

export function oprateMinion ({state, commit}, payload) {
  Dialog.create({
    title: '操作主机',
    message: '确定要执行该操作？',
    ok: '跑路',
    cancel: '再想想'
  }).then(() => {
    post('/salt/oprate_keys/', {
      opration: payload.opration,
      minion: payload.minion
    }).then((response) => {
      this.dispatch('minions/loadTable')
    }).catch((error) => {
      alert(error.response.data)
      this.dispatch('minions/loadTable')
    })
  }).catch(() => {
    console.log('stay')
  })
}
